package com.example.yichuangyun.dialog;

import android.content.Context;
import android.view.View;

import androidx.core.content.ContextCompat;

import com.example.yichuangyun.R;
import com.example.yichuangyun.databinding.DialogChooseModelBinding;

public abstract class ChooseModelDialog extends BaseCommonDialog<DialogChooseModelBinding> {

    private boolean isDb;

    public ChooseModelDialog(Context context, boolean isDb) {
        super(context);
        this.isDb = isDb;
    }

    @Override
    protected void initView() {
        setCancelable(true);
        setStyle();
        mBinding.closeIv.setOnClickListener(view -> dismiss());
        mBinding.ailModelRl.setOnClickListener(view -> {
            setStyle();
            isDb = !isDb;
            chooseModel(isDb);
            dismiss();
        });

        mBinding.dbModelRl.setOnClickListener(view -> {
            setStyle();
            isDb = !isDb;
            chooseModel(isDb);
            dismiss();
        });
    }

    private void setStyle() {
        if (isDb) {
            mBinding.dbModelTv.setTextColor(ContextCompat.getColor(mContext, R.color.color_426FFF));
            mBinding.dbCheckedIv.setVisibility(View.VISIBLE);
            mBinding.ailModelTv.setTextColor(ContextCompat.getColor(mContext, R.color.color_444444));
            mBinding.aliIv.setImageResource(R.mipmap.icon_ali);
            mBinding.aliCheckedIv.setVisibility(View.GONE);
        } else {
            mBinding.ailModelTv.setTextColor(ContextCompat.getColor(mContext, R.color.color_426FFF));
            mBinding.aliCheckedIv.setVisibility(View.VISIBLE);
            mBinding.dbModelTv.setTextColor(ContextCompat.getColor(mContext, R.color.color_444444));
            mBinding.aliIv.setImageResource(R.mipmap.icon_ali2);
            mBinding.dbCheckedIv.setVisibility(View.GONE);
        }
    }

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_choose_model;
    }

    public abstract void chooseModel(boolean b);

}
